package com.cn.yugan.Engine.Adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cn.yugan.Engine.Holder.OrlItemHolder;
import com.cn.yugan.Engine.Beans.ArticleListInfo;
import com.cn.yugan.mobile.R;

import java.util.ArrayList;

/**
 * Created by Rover on 2016/7/22 .
 * Email 357319517@qq.com
 */
public class OriListViewAdpater extends BaseAdapter {
    private Context context;
    private ArrayList<ArticleListInfo> mlist;
    private LayoutInflater layoutInflater;
    private OrlItemHolder orlItemHolder;

    public OriListViewAdpater(Context context, ArrayList<ArticleListInfo> mlist) {
        this.context = context;
        this.mlist = mlist;
        this.layoutInflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        orlItemHolder = null;
        if (convertView == null) {
            orlItemHolder = new OrlItemHolder();
            convertView = layoutInflater.inflate(R.layout.list_item_collection, null);
            orlItemHolder.status = (TextView) convertView.findViewById(R.id.list_item_collection_aid);
            orlItemHolder.title = (TextView) convertView.findViewById(R.id.list_item_collection_title);
            orlItemHolder.aid = (TextView) convertView.findViewById(R.id.list_item_collection_time);
            convertView.setTag(orlItemHolder);
        } else {
            orlItemHolder = (OrlItemHolder) convertView.getTag();
        }
        String title = mlist.get(position).getTitle();
        orlItemHolder.title.setText(Html.fromHtml(title));
        orlItemHolder.aid.setText("yg" + mlist.get(position).getAid());
        switch (mlist.get(position).getStatus()) {
            case 0: {
                orlItemHolder.status.setTextColor(context.getResources().getColor(R.color.tianyiblue));
                orlItemHolder.status.setText("待审核");
                break;
            }
            case 1: {
                orlItemHolder.status.setTextColor(context.getResources().getColor(R.color.color_darkgreen));
                orlItemHolder.status.setText("通过");
                break;
            }
            case 2: {
                orlItemHolder.status.setTextColor(Color.RED);
                orlItemHolder.status.setText("未通过");
                break;
            }
        }


        return convertView;
    }

    public void refreshList(ArrayList<ArticleListInfo> mlist) {
        if (mlist == null) {

        } else {
            this.mlist = mlist;
        }

    }

    public void addList(ArrayList<ArticleListInfo> mlist) {
        if (mlist == null) {

        } else {
            this.mlist.addAll(mlist);
        }

    }
}
